#pragma once
#include <WinSock2.h>
#include "IOCP_Define.h"

namespace Next
{
	namespace Protocols
	{
		using namespace Defines::IOCP_Define;

		class EXWSAOVERLAPPED
		{
		public:
			EXWSAOVERLAPPED()
			{
				stOverLapped.Internal = 0;
				stOverLapped.InternalHigh = 0;
				stOverLapped.Offset = 0;
				stOverLapped.OffsetHigh = 0;
				stOverLapped.hEvent = NULL;
			}

			WSAOVERLAPPED	stOverLapped;
			Io_Mode			eIoMode;
		};

		class CIoContext
		{
		public:
			CIoContext()
			{
				stBuf.buf = NULL;
				stBuf.len = 0;
			}

			void SetIoMode(Io_Mode iomode)
			{
				cExOverlapped.eIoMode = iomode;
			}

			EXWSAOVERLAPPED	cExOverlapped;
			WSABUF			stBuf;
			char			vMessageBuffer[MAX_IO_BUFFERSIZE];
		};

		class CIocp : public TSingleton<CIocp>
		{
			friend class TSingleton<CIocp>;

		protected:
			CIocp();
			~CIocp();

		public:
			bool Init();
			void Clear();
			bool Start();

		private:
			SOCKET			upListenSock;
			HANDLE			hIOCP;
			unsigned int	vWorkerThread[MAX_WORKER_THREADS];
			//unsigned int	uManagerThread;
			
			unsigned short	uPort;
			unsigned long	uThreadCount;

			unsigned long	uTotalSendMessageSize;
			unsigned long	uTotalRecvMessageSize;
		};
	}
}